var vm = new Vue({
    el: '#rrapp',
    data: {
        activeName: 'first',
        standard: {
            title: '',
            dialogFormVisible: false,
            currentRow: {},
            goodsCraftConfigData: [],//标品工艺价格配置
            query: {
                craftName: null,
            },
            page: {
                currentPage: 0,
                pageSizes: [15, 30, 50],
                pageSize: 15, total: 0,
                ascending: [],
                descending: []
            },
        },
        print: {
            title: '',
            dialogFormVisible: false,
            currentRow: {},
            goodsCraftConfigData: [],//报价工艺价格配置
            query: {
                craftName: null,
            },
            page: {
                currentPage: 0,
                pageSizes: [15, 30, 50],
                pageSize: 15, total: 0,
                ascending: [],
                descending: []
            },
        },
        fast: {
            title: '',
            dialogFormVisible: false,
            currentRow: {},
            goodsCraftConfigData: [],//报价工艺价格配置
            query: {
                craftName: null,
            },
            page: {
                currentPage: 0,
                pageSizes: [15, 30, 50],
                pageSize: 15, total: 0,
                ascending: [],
                descending: []
            },
        },
    },
    mounted: function () {
        this.queryPrint();
    },
    methods: {
        queryPrint: function () {
            var queryParam = this.print.query;
            queryParam.attributeSearchType = 'print';
            queryParam.attributeOrigin = 'print_craft';
            // 分页参数
            queryParam.page = this.print.page.currentPage;
            queryParam.limit = this.print.page.pageSize;

            //ajax 请求
            $.ajax({
                type: "POST",
                url: baseURL + "craftConfig/goodscraftconfig/listQuote",
                contentType: "application/json",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    if (r.code == 0) {
                        vm.print.page.total = r.page.totalCount;
                        vm.print.goodsCraftConfigData = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },

        searchPrint: function () {
            this.print.page.currentPage = 0;
            this.queryPrint();
        },
        // 报价工艺页数变化
        handlePrintSizeChange: function (val) {
            this.print.page.pageSize = val;
            this.queryPrint();
        },
        //报价工艺当前页变化
        handlePrintCurrentChange: function (val) {
            this.print.page.currentPage = val;
            this.queryPrint();
        },

        //编辑商务印刷商品工艺
        editPrint: function (index, row) {
            this.print.title = row.craftName + " 工艺配置编辑";
            //克隆一个row
            var newObject = jQuery.extend(true, {}, row);
            newObject.endPartCount = String(newObject.endPartCount);
            this.print.currentRow = newObject;
            this.print.dialogFormVisible = true;
        },

        // 保存/编辑 商务印刷工艺配置
        saveOrUpdatePrint: function (row) {
            row.attributeOrigin = 'print_craft';
            var self = this;
            // 提示框 准备提现
            this.$confirm('确认更改' + row.craftName + '工艺配置?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //ajax 提交 请求保存
                $.ajax({
                    type: "POST",
                    url: baseURL + "craftConfig/goodscraftconfig/saveOrUpdate",
                    contentType: "application/json",
                    data: JSON.stringify(row),
                    success: function (r) {
                        if (r.code == 0) {
                            self.$message({
                                type: 'success',
                                message: '保存成功!'
                            });
                            self.print.dialogFormVisible = false;
                            self.queryPrint();
                        } else {
                            alert(r.msg);
                        }
                    }
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提现'
                });
            });
        },

        /*switchChange: function (row) {
            //取出id 和状态ajax 异步请求更改
            var text = "启用";
            if(row.delFlag == 1){ // 停用
                text = "停用";
            }
            var self = this;
            var data = {id:row.id, delFlag: row.delFlag};
            // 提示框 准备修改状态
            this.$confirm('确认'+text + row.craftName+" 配置?", '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //ajax 提交 请求保存
                $.ajax({
                    type: "POST",
                    url: baseURL + "craftConfig/goodscraftconfig/updateDelFlag",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    success: function (r) {
                        if (r.code == 0) {
                            self.$message({
                                type: 'success',
                                message: '保存成功!'
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消更改'
                });
                if(row.delFlag == 1){
                    row.delFlag == 0;
                }else {
                    row.delFlag == 1;
                }
            });
        },*/

        queryFast: function () {
            var queryParam = this.fast.query;
            queryParam.attributeSearchType = 'fast';
            queryParam.attributeOrigin = 'fast_craft';

            // 分页参数
            queryParam.page = this.fast.page.currentPage;
            queryParam.limit = this.fast.page.pageSize;

            //ajax 请求
            $.ajax({
                type: "POST",
                url: baseURL + "craftConfig/goodscraftconfig/listQuote",
                contentType: "application/json",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    if (r.code == 0) {
                        vm.fast.page.total = r.page.totalCount;
                        vm.fast.goodsCraftConfigData = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },

        searchFast: function () {
            this.fast.page.currentPage = 0;
            this.queryFast();
        },
        // 数码快印工艺页数变化
        handleFastSizeChange: function (val) {
            this.fast.page.pageSize = val;
            this.queryFast();
        },
        //报价工艺当前页变化
        handleFastCurrentChange: function (val) {
            this.fast.page.currentPage = val;
            this.queryFast();
        },

        //编辑报价商品工艺
        editFast: function (index, row) {
            this.fast.title = row.craftName + " 工艺配置编辑";
            //克隆一个row
            var newObject = jQuery.extend(true, {}, row);
            newObject.endPartCount = String(newObject.endPartCount);
            this.fast.currentRow = newObject;
            this.fast.dialogFormVisible = true;
        },

        // 保存/编辑 数码快印工艺配置
        saveOrUpdateFast: function (row) {
            row.attributeOrigin = 'fast_craft';
            var self = this;
            // 提示框 准备保存
            this.$confirm('确认更改' + row.craftName + '工艺配置?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //ajax 提交 请求保存
                $.ajax({
                    type: "POST",
                    url: baseURL + "craftConfig/goodscraftconfig/saveOrUpdate",
                    contentType: "application/json",
                    data: JSON.stringify(row),
                    success: function (r) {
                        if (r.code == 0) {
                            self.$message({
                                type: 'success',
                                message: '保存成功!'
                            });
                            self.fast.dialogFormVisible = false;
                            self.queryFast();
                        } else {
                            alert(r.msg);
                        }
                    }
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提现'
                });
            });
        },

        queryStandard: function () {
            var queryParam = this.standard.query;
            // 分页参数
            queryParam.page = this.standard.page.currentPage;
            queryParam.limit = this.standard.page.pageSize;

            //ajax 请求
            $.ajax({
                type: "POST",
                url: baseURL + "craftConfig/goodscraftconfig/listStandard",
                contentType: "application/json",
                data: JSON.stringify(queryParam),
                success: function (r) {
                    if (r.code == 0) {
                        vm.standard.page.total = r.page.totalCount;
                        vm.standard.goodsCraftConfigData = r.page.list;
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },

        searchStandard: function () {
            this.standard.page.currentPage = 0;
            this.queryStandard();
        },

        // 标品工艺页数变化
        handleStandardSizeChange: function (val) {
            this.standard.page.pageSize = val;
            this.queryStandard();
        },
        //标品工艺当前页变化
        handleStandardCurrentChange: function (val) {
            this.standard.page.currentPage = val;
            this.queryStandard();
        },

        //编辑标品工艺
        editStandard: function (index, row) {
            this.standard.title = row.craftName + " 工艺配置编辑";
            //克隆一个row
            var newObject = jQuery.extend(true, {}, row);
            this.standard.currentRow = newObject;
            this.standard.dialogFormVisible = true;
        },

        // 保存/编辑 标品工艺配置
        saveOrUpdateStandard: function (row) {
            row.attributeOrigin = 'standard_craft';
            var self = this;
            // 提示框 准备提现
            this.$confirm('确认更改' + row.craftName + '工艺配置?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //ajax 提交 请求保存
                $.ajax({
                    type: "POST",
                    url: baseURL + "craftConfig/goodscraftconfig/saveOrUpdate",
                    contentType: "application/json",
                    data: JSON.stringify(row),
                    success: function (r) {
                        if (r.code == 0) {
                            self.$message({
                                type: 'success',
                                message: '保存成功!'
                            });
                            self.standard.dialogFormVisible = false;
                            self.queryStandard();
                        } else {
                            alert(r.msg);
                        }
                    }
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提现'
                });
            });
        },
    }
});